/**
 * @FileName: auto-dark.ts
 * @Description: // 动态主题组合api
 * @Author: Ellwood(liugangsin@qq.com)
 * @CreateDate: 2025/2/5 - 16:43
 * @Version: V1.0.0
 */

export const isDark = useDark();

export const toggleDark = useToggle(isDark);

export const useAutoDark = () => {
  const isPrefersDark = usePreferredDark();
  const appStore = useAppStore();

  watch(
    isPrefersDark,
    (isDark) => {
      if (isDark) {
        appStore.updateLayoutStyle("dark");
        toggleDark(isDark);
      } else {
        appStore.updateLayoutStyle("light");
        toggleDark(isDark);
      }
    },
    { immediate: true },
  );
};
